package ged.extension.point.definition.handlers;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;

public class EvaluateContributionConnectionShapes {

	//Access any extensions that have been created for this extension point
	private static final String ICUSTOM_CONNECTION_SHAPE_ID = 
			"ged.extension.point.definition.connection.shapes";
	static Map<String, Object> map=new HashMap<String, Object>();
	Object newConnectionShape = null;
	
	private static EvaluateContributionConnectionShapes instance;
	protected EvaluateContributionConnectionShapes () {
		
	}
	
	public static EvaluateContributionConnectionShapes getInstance() {
		if(instance == null)
		{
			instance = new EvaluateContributionConnectionShapes();
		}
		return instance;
	}
	
	public Map<String, Object> evaluateConnectionShapes() {
		//Extension Registry - API which returns the extension points - Get Extension Registry
		IExtensionRegistry registry = Platform.getExtensionRegistry();
		//Read all the extension
		/**
		 * Configuration elements are object representations of the XML elements under the <extension> tag in the plugin.xml files
		 */
		IConfigurationElement[] config = registry
				.getConfigurationElementsFor(ICUSTOM_CONNECTION_SHAPE_ID);
				
		Map<String, Object> returnedMap = new HashMap<String, Object>();
		for (int i = 0; i < config.length; i++) 
		{
			IConfigurationElement element = config[i];
			String name = element.getAttribute("name");
			String uniqueID = element.getAttribute("id");
			
			try {
				newConnectionShape = element.createExecutableExtension("class");
			} catch (CoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			map.put(name, newConnectionShape);
		}
		return map;
	}
}
